/**
 * Solution.java
 */
package dateconversion;

import java.util.Stack;

/**
 * @author prakash
 *
 */
public class Solution3 {

	public static void main(String args[]) throws Exception {

		System.out.println(braces("{}[]("));
	}

	static int maxRounds(String s, String t) {
		int maxRounds = 0;
		int replaceStringSize = t.length();
		StringBuilder src = new StringBuilder(s);
		int index = -1;
		while ((index = src.indexOf(t)) != -1) {
			src.replace(index, index + replaceStringSize, "");
			maxRounds++;
		}
		return maxRounds;
	}

	private String REG_EXP_FOR_ROMAN_NUM = "^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$";

	static String braces(String value) {

		Stack<Character> stack = new Stack<Character>();

		for (int index = 0; index < value.length(); index++) {
			Character topEl = stack.isEmpty() ? ' ' : stack.peek();
			Character curChar = value.charAt(index);
			if (isMatching(topEl, curChar)) {
				stack.pop();
			} else {
				stack.push(curChar);
			}

		}
		if (stack.isEmpty()) {
			return "YES";
		}

		return "NO";
	}

	private static boolean isMatching(char top, char ele) {
		switch (top) {
		
		case '{':
			if (ele == '}')
				return true;
			else
				return false;
		case '[':
			if (ele == ']')
				return true;
			else
				return false;
		case '(':
			if (ele == ')')
				return true;
			else
				return false;
		default:
			return false;
		}
	}
}
